package com.doubi.controller.sysDic;//package com.gaoguo.controller;

import com.doubi.common.aspectj.annotation.SysLog;
import com.doubi.model.sys.TCity;
import com.doubi.service.CityService;
import com.doubi.utils.DataUtil;
import com.doubi.vo.AppModel;
import com.doubi.vo.PageVo;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 市区 信息操作处理
 * @author MrDoubi
 * @date 2019-05-29 20:09:19
 */
@Controller
@RequestMapping("city")
public class CityController {

    @Autowired
    private CityService cityService;

    /**
     * 功能描述：进入页面
     * @author   MrDoubi 2019-06-29 16:40
     * @param provinceOid       省oid
     * @param model             model
     * @return                  返回页面路径
     */
    @RequiresPermissions("city:view")
    @GetMapping("view")
    public String list(String provinceOid, Model model) {
        model.addAttribute("provinceOid",provinceOid);
        return "web/city/view";
    }

    /**
     * 功能说明：查询市区分页列表
     * @author MrDoubi
     * @date 2019-05-29 20:09:19
     */
    @SysLog(title = "查询市区分页列表")
    @RequiresPermissions("city:page")
    @PostMapping("page")
    @ResponseBody
    public PageVo<TCity> getPage(PageVo<TCity> page, TCity city) {
        return cityService.getPage(page, city);
    }


    /**
     * 查询市区列表
     *
     * @author MrDoubi
     * @date 2019-05-29 20:09:19
     */
    @RequiresPermissions("city:list")
    @PostMapping("list")
    @ResponseBody
    public List<TCity> getList(TCity city) {
        return cityService.getList(city);
    }

    /**
     * 功能说明：修改市区
     * @author MrDoubi
     * @date 2019-05-29 20:09:19
     */
    @RequiresPermissions(value = {"city:edit", "city:add"}, logical = Logical.OR)
    @GetMapping("edit")
    public String edit(TCity city, Model model) {
        if (DataUtil.isNotEmpty(city.getCityOid())) {
            city = cityService.getById(city.getCityOid());
        }
        model.addAttribute("bean", city);
        return "web/city/edit";
    }

    /**
     * 功能说明：保存市区
     * @author MrDoubi
     * @date 2019-05-29 20:09:19
     */
    @SysLog(title = "保存市区")
    @RequiresPermissions("city:saveOrUpdate")
    @PostMapping("saveOrUpdate")
    @ResponseBody
    public AppModel saveOrUpdate(TCity city) {
        return cityService.saveOrUpdateBean(city);
    }

    /**
     * 功能说明：删除市区
     * @author MrDoubi
     * @date 2019-05-29 20:09:19
     */
    @SysLog(title = "删除市区")
    @RequiresPermissions("city:delBean")
    @PostMapping("delBean")
    @ResponseBody
    public AppModel delBean(TCity city) {
        return cityService.delBean(city);
    }

    /**
     * 功能说明：市区状态更新 接口
     * @author  MrDoubi 2019-01-10 15:14:33
     * @param city bean
     * @return model
     */
    @SysLog(title = "市区状态更新 接口")
    @RequiresPermissions("city:updateStatus")
    @PostMapping("updateStatus")
    @ResponseBody
    public AppModel updateStatus(TCity city){
        return cityService.updateStatus(city);
    }

}
